﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using TakaGUI.Services;
using TakaGUI;
using EvoSim.RandomNumberGenerators;
using System.Diagnostics;

namespace EvoSim
{
	public static class Globals
	{
		public static Window GameScreen;

		public static ICursorManager CursorManager;
		public static IDebug Debug;
		public static IGraphicsManager GraphicsManager;
		public static IKeyboardInput KeyboardInput;
		public static IMouseInput MouseInput;
		public static IResourceManager ResourceManager;
		public static IGUIManager GUIManager;

		public static UniformRandomGenerator Random;
		public static NormalRandomGenerator GaussianRandom;
	}

	[DebuggerDisplay("Value={Value}, Min={Min}, Max={Max}")]
	public struct DoubleMinMax
	{
		double _Value;
		public double Value
		{
			get { return _Value; }
			set
			{
				_Value = value;

				if (Min != -1 && _Value < Min)
					_Value = Min;

				if (Max != -1 && _Value > Max)
					_Value = Max;
			}
		}

		double _Min;
		public double Min
		{
			get { return _Min; }
			set
			{
				_Min = value;

				if (_Min == -1)
					return;

				if (_Min > _Max)
					_Min = _Max;

				Value = Value;
			}
		}

		double _Max;
		public double Max
		{
			get { return _Max; }
			set
			{
				_Max = value;

				if (_Max == -1)
					return;

				if (_Max < _Min)
					_Max = _Min;

				Value = Value;
			}
		}

		public DoubleMinMax(double min, double max)
		{
			_Value = 0;
			_Min = 0;
			_Max = 0;

			Min = min;
			Max = max;
		}

		public void SetToMin()
		{
			Value = Min;
		}
		public void SetToMax()
		{
			Value = Max;
		}
	}

	[DebuggerDisplay("Value={Value}, Min={Min}, Max={Max}")]
	public struct IntMinMax
	{
		int _Value;
		public int Value
		{
			get { return _Value; }
			set
			{
				_Value = value;

				if (Min != -1 && _Value < Min)
					_Value = Min;

				if (Max != -1 && _Value > Max)
					_Value = Max;
			}
		}

		int _Min;
		public int Min
		{
			get { return _Min; }
			set
			{
				_Min = value;

				if (_Min == -1)
					return;

				if (_Min > _Max)
					_Min = _Max;

				Value = Value;
			}
		}

		int _Max;
		public int Max
		{
			get { return _Max; }
			set
			{
				_Max = value;

				if (_Max == -1)
					return;

				if (_Max < _Min)
					_Max = _Min;

				Value = Value;
			}
		}

		public IntMinMax(int min, int max)
		{
			_Value = 0;
			_Min = 0;
			_Max = 0;

			Min = min;
			Max = max;
		}

		public void SetToMin()
		{
			Value = Min;
		}
		public void SetToMax()
		{
			Value = Max;
		}
	}
}
